package org.lboot.flow.provider;

import cn.hutool.core.lang.Validator;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lboot.flow.FlowCtl;
import org.lboot.flow.FlowEventCtl;
import org.lboot.flow.event.FlowEventConsumer;
import org.lboot.flow.module.event.FlowCustomEvent;
import org.lboot.flow.module.work.FlowWork;
import org.lboot.flow.module.work.FlowWorkService;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class DefaultFlowEventCtlImpl implements FlowEventCtl {
    // 事件消费者列表
    List<FlowEventConsumer> consumers;

    FlowWorkService flowWorkService;

    @Override
    public void processEventChain(List<FlowCustomEvent> events) {

        for (FlowCustomEvent event:events){
            processEvent(event);
        }
    }



    @Override
    public void processEvent(FlowCustomEvent event) {
        // 同步事件，需要修改流程实例状态
        if (event.getIsAsync().equals(false)){
            //
        }
        for (FlowEventConsumer consumer:consumers){
            if (event.getEventId().equals(consumer.eventId())){
                 consumer.consume(event);
            }
        }
    }
}
